<?php
//   +----------------------------------------------------------------------
//   | Copyright (c) 2015-2025 http://www.hdphp.cn All rights reserved.
//   | Licensed ( http://www.hdphp.cn/licenses/ )
//   | Author: Jack <sophia2152@qq.com>
//   | 官方网址: http://www.hdphp.cn
//   | 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
//   | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
//   +----------------------------------------------------------------------

use app\common\http\middleware\AllowOriginMiddleware;
use app\common\http\middleware\InstallMiddleware;
use think\facade\Config;
use think\facade\Route;
use think\Response;

// +----------------------------------------------------------------------
// | 后台管理路由配置
// +----------------------------------------------------------------------
Route::group('adminapi', function () {

    /**
     * 无需授权的接口
     */
    Route::group(function () {
        // 测试地址
        Route::get('index', 'Test/index')->option(['real_name' => '测试地址']);

        // 用户名密码登录
        Route::post('login', 'Login/login')->name('AdminLogin')->option(['real_name' => '用户名密码登录']);
        // 短信登录
        Route::post('m_login', 'Login/mobileLogin')->name('mobileLogin')->option(['real_name' => '短信登录']);
        // 短信重置密码
        Route::post('reset_pwd', 'Login/resetPwd')->name('resetPwd')->option(['real_name' => '短信重置密码']);
    });

    /**
     * 系统设置维护 系统权限管理、系统菜单管理 系统配置 相关路由
     */
    Route::group('setting', function () {

        /* 管理员相关路由 */
        // 获取管理员列表
        Route::get('admin/list', 'v1.system.admin.SystemAdmin/index')->name('SystemAdminList')->option(['real_name' => '获取管理员列表']);
        // 创建管理员
        Route::post('admin/create', 'v1.system.admin.SystemAdmin/add')->name('SystemAdminCreate')->option(['real_name' => '创建管理员']);
        // 修改管理员
        Route::put('admin/update/:id', 'v1.system.admin.SystemAdmin/edit')->name('SystemAdminUpdate')->option(['real_name' => '修改管理员']);
        // 设置管理员状态
        Route::put('admin/set_status/:id/:status', 'v1.system.admin.SystemAdmin/set_status')->name('SystemAdminSetStatus')->option(['real_name' => '设置管理员状态']);
        // 删除管理员
        Route::delete('admin/delete/:id', 'v1.system.admin.SystemAdmin/delete')->name('SystemAdminDelete')->option(['real_name' => '删除管理员']);
        // 获取当前登陆管理员的信息
        Route::get('admin/admin_info', 'v1.system.admin.SystemAdmin/admin_info')->name('SystemAdminAdminInfo')->option(['real_name' => '获取当前登陆管理员的信息']);
        // 修改当前登陆的管理员信息
        Route::put('admin/admin_update', 'v1.system.admin.SystemAdmin/update_admin')->name('SystemAdminUpdateAdmin')->option(['real_name' => '修改当前登陆的管理员信息']);

        /* 角色相关路由 */
        // 获取角色列表
        Route::get('role/list', 'v1.system.SystemRole/index')->name('SystemRoleList')->option(['real_name' => '获取角色列表']);
        // 创建角色
        Route::post('role/create', 'v1.system.SystemRole/add')->name('SystemRoleCreate')->option(['real_name' => '创建角色']);
        // 修改角色
        Route::put('role/update/:id', 'v1.system.SystemRole/edit')->name('SystemRoleUpdate')->option(['real_name' => '修改角色']);
        // 设置角色状态
        Route::put('role/set_status/:id/:status', 'v1.system.SystemRole/set_status')->name('SystemRoleSetStatus')->option(['real_name' => '设置角色状态']);
        // 删除角色
        Route::delete('role/delete/:id', 'v1.system.SystemRole/delete')->name('SystemRoleDelete')->option(['real_name' => '删除角色']);

        /* 菜单相关路由 */
        // 获取菜单列表
        Route::get('menus/list', 'v1.system.SystemMenus/index')->name('SystemMenusList')->option(['real_name' => '获取菜单列表']);
        // 创建菜单
        Route::post('menus/create', 'v1.system.SystemMenus/add')->name('SystemMenusCreate')->option(['real_name' => '创建菜单']);
        // 修改菜单
        Route::put('menus/update/:id', 'v1.system.SystemMenus/edit')->name('SystemMenusUpdate')->option(['real_name' => '修改菜单']);
        // 删除菜单
        Route::delete('menus/delete/:id', 'v1.system.SystemMenus/delete')->name('SystemMenusDelete')->option(['real_name' => '删除菜单']);

        /* 云存储配置相关路由 */
        // 云存储列表
        Route::get('config/storage', 'v1.system.config.SystemStorage/index')->name('SystemStorageIndex')->option(['real_name' => '云存储列表']);
        // 获取云存储配置
        Route::get('config/storage/config', 'v1.system.config.SystemStorage/getConfig')->name('SystemStorageConfig')->option(['real_name' => '获取云存储配置']);
        // 同步云存储列表
        Route::put('config/storage/syncs/:type', 'v1.system.config.SystemStorage/syncs')->name('SystemStorageSyncs')->option(['real_name' => '同步云存储列表']);


        // 修改云存储状态
        Route::put('config/storage/status/:id', 'v1.system.config.SystemStorage/status')->name('SystemStorageStatus')->option(['real_name' => '修改云存储状态']);


        // 选择存储方式
        Route::get('config/storage/save_type/:type', 'v1.system.config.SystemStorage/uploadType')->name('SystemStorageUploadType')->option(['real_name' => '选择存储方式']);


    })->middleware([
        \app\common\http\middleware\admin\AdminAuthTokenMiddleware::class,
        \app\common\http\middleware\admin\AdminCkeckRoleMiddleware::class,
        \app\common\http\middleware\admin\AdminLogMiddleware::class
    ]);

    /**
     * 维护 相关路由
     */
    Route::group('system', function () {
        // 退出登陆
        Route::get('admin/logout', 'v1.system.admin.SystemAdmin/logout')->name('SystemAdminLogout')->option(['real_name' => '退出登陆']);
        // 系统日志
        Route::get('log', 'v1.system.log.SystemLog/index')->name('SystemLog')->option(['real_name' => '系统日志']);
        // 登录日志
        Route::get('login/log', 'v1.system.log.SystemLoginLog/index')->name('SystemLoginLog')->option(['real_name' => '登录日志']);
        // 系统日志管理员搜索条件
        Route::get('log/search_admin', 'v1.system.log.SystemLog/search_admin')->option(['real_name' => '下拉搜索条件']);

    })->middleware([
        \app\common\http\middleware\admin\AdminAuthTokenMiddleware::class,
        \app\common\http\middleware\admin\AdminCkeckRoleMiddleware::class,
        \app\common\http\middleware\admin\AdminLogMiddleware::class
    ]);

    /**
     * 附件相关路由
     */
    Route::group('file', function () {
        // 附件分类列表
        Route::get('category/list', 'v1.system.attachment.SystemAttachmentCategory/index')->name('CategoryList')->option(['real_name' => '附件分类列表']);
        // 创建附件分类
        Route::post('category/create', 'v1.system.attachment.SystemAttachmentCategory/add')->name('CategoryCreate')->option(['real_name' => '创建附件分类']);
        // 修改附件分类
        Route::put('category/update/:id', 'v1.system.attachment.SystemAttachmentCategory/edit')->name('CategoryUpdate')->option(['real_name' => '修改附件分类']);
        // 删除附件分类
        Route::delete('category/delete/:id', 'v1.system.attachment.SystemAttachmentCategory/delete')->name('CategoryDelete')->option(['real_name' => '删除附件分类']);


        // 附件列表
        Route::get('list', 'v1.system.attachment.SystemAttachment/index')->option(['real_name' => '附件列表']);
        // 删除附件
        Route::post('delete', 'v1.system.attachment.SystemAttachment/delete')->option(['real_name' => '删除附件']);
        // 上传图片
        Route::post('upload/[:upload_type]', 'v1.system.attachment.SystemAttachment/upload')->option(['real_name' => '上传图片']);

//        //移动图片分类表单
//        Route::get('file/move', 'v1.system.attachment.SystemAttachment/move')->option(['real_name' => '移动图片分类表单']);
//        //移动图片分类
//        Route::put('file/do_move', 'v1.system.attachment.SystemAttachment/moveImageCate')->option(['real_name' => '移动图片分类']);
//        //修改图片名称
//        Route::put('file/update/:id', 'v1.system.attachment.SystemAttachment/update')->option(['real_name' => '修改图片名称']);

//        //获取上传类型
//        Route::get('upload_type', 'v1.system.attachment.SystemAttachment/uploadType')->option(['real_name' => '上传类型']);
//        //分片上传本地视频
//        Route::post('video_upload', 'v1.system.attachment.SystemAttachment/videoUpload')->option(['real_name' => '分片上传本地视频']);
//        //oss视频素材保存
//        Route::post('video_attachment', 'v1.system.attachment.SystemAttachment/saveVideoAttachment')->option(['real_name' => '视频素材保存']);
//
//        //获取扫码上传页面链接以及参数
//        Route::get('scan/qrcode', 'v1.system.attachment.SystemAttachment/scanUploadQrcode')->option(['real_name' => '获取扫码上传页面链接以及参数']);
//        //删除二维码
//        Route::get('remove/qrcode', 'v1.system.attachment.SystemAttachment/removeUploadQrcode')->option(['real_name' => '删除二维码']);
//        //获取扫码上传的图片数据
//        Route::get('scan/image/list/:scan_token', 'v1.system.attachment.SystemAttachment/scanUploadImage')->option(['real_name' => '获取扫码上传的图片数据']);
//        //网络图片上传
//        Route::post('online/upload', 'v1.system.attachment.SystemAttachment/onlineUpload')->option(['real_name' => '网络图片上传']);
//
//        //获取上传信息
//        Route::get('get/way_data', 'v1.system.attachment.SystemAttachment/getAdminsData')->option(['real_name' => '获取上传信息']);
//        //保存上传信息
//        Route::get('set/way_data/:is_way', 'v1.system.attachment.SystemAttachment/setAdminsData')->option(['real_name' => '保存上传信息']);


    })->middleware([
        \app\common\http\middleware\admin\AdminAuthTokenMiddleware::class,
        \app\common\http\middleware\admin\AdminCkeckRoleMiddleware::class,
        \app\common\http\middleware\admin\AdminLogMiddleware::class
    ]);

    /**
     * miss 路由
     */
    Route::miss(function () {
        if (app()->request->isOptions()) {
            $header = Config::get('cookie.header');
            $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
            return Response::create('ok')->code(200)->header($header);
        } else {
            return Response::create()->code(404);
        }
    });
})->prefix('admin.')->middleware(InstallMiddleware::class)->middleware(AllowOriginMiddleware::class);
